home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / manual-p / vh-man2h.000 / vh-man2h / vh-man2html-1.3 / mansec < prev    next >
Text File  |  1996-05-03  |  5KB  |  147 lines

  1. #!/usr/bin/awk -f
  2. #
  3. #  Generate an index into a manual section by using find.
  4. #  Michael Hamilton <michael@actrix.gen.nz>
  5. #
  6. BEGIN {
  7.  
  8.   OFS="";
  9.   section = ARGV[1];
  10.   "echo $PPID" | getline pid;
  11.  
  12.   if (section !~ /^[0-9]$/ && section != "all") {
  13.     print "Content-type: text/html\n\n";  
  14.     print "<head>";
  15.     print "<title>Manual - Illegal section</title>";
  16.     print "<body>";
  17.     print "Illegal section number '" section "'." ;
  18.     print "Must be 0..9 or all";
  19.     print "</body>";
  20.     exit;
  21.   }
  22.     
  23.   whatis_db  = "/usr/man/whatis";
  24.   cache_dir  = "/var/man2html";
  25.   cache_file = "manindex-" section ".html";
  26.   cache = cache_dir "/" cache_file;
  27.   cache_tmp = cache "_" pid;
  28.   buffer_tmp = cache "_items_" pid;
  29.                 # Find out the man path
  30.   "/usr/bin/man -w" | getline man_path
  31.   man_path = man_path ":";
  32.   gsub(":", " ", man_path);
  33.                 # See if anything is out of date.
  34.   if (section == "all") {
  35.     if (system("test -f " cache) == 0) {
  36.       cmd = "/usr/bin/find " man_path " -maxdepth 1 -name 'man[0-9]' -newer " cache;
  37.       cmd | getline need_update;
  38.     }
  39.     else {
  40.       need_update = 1;
  41.     }
  42.   }
  43.   else {
  44.     if (system("test -f " cache) == 0) {
  45.       cmd = "/usr/bin/find " man_path " -maxdepth 1 -name man" section " -newer " cache;
  46.       cmd | getline need_update;
  47.     }
  48.     else {
  49.       need_update = 1;
  50.     }
  51.   }
  52.  
  53.   cmd = "/usr/bin/find " cache_dir " -maxdepth 1 -name " cache_file " -newer " whatis_db;
  54.   cmd | getline predone;
  55.  
  56.   if (need_update != "") {
  57.     sec_name[1] = "User Commands";
  58.     sec_name[2] = "System Calls";
  59.     sec_name[3] = "Library Functions";
  60.     sec_name[4] = "Special Files";
  61.     sec_name[5] = "File Formats";
  62.     sec_name[6] = "Games";
  63.     sec_name[7] = "Miscellany";
  64.     sec_name[8] = "Administration and Privileged Commands";
  65.     sec_name["all"] = "All available manual pages";
  66.  
  67.                 # Print heading
  68.     print "Content-type: text/html\n\n" > cache_tmp;  
  69.     print "<html>\n<head>" > cache_tmp;
  70.     print "<title>Manual Pages - Names: " section ". " sec_name[section] "</title>"> cache_tmp;
  71.     print "</head>\n<body>" > cache_tmp;
  72.     print "<h1>Manual Pages - Page Names</h1>" > cache_tmp;
  73.     print "<h2>Section " section ": " sec_name[section] "</h2>" > cache_tmp;
  74.     
  75.     "hostname" | getline hostname;
  76.     "date" | getline date;
  77.     print hostname " (" date ")" > cache_tmp;
  78.     
  79.     if (section != "all") {
  80.       sec_sub_dir = "/man" section;
  81.     }
  82.     else {
  83.       sec_sub_dir = "/man*";    
  84.     }
  85.     gsub(" ", sec_sub_dir " ", man_path); 
  86.     
  87.     print "<p>Manual pages found under " man_path "." > cache_tmp;
  88.  
  89.                 # Find any man[0-9]/filenames
  90.     while ("/usr/bin/find " man_path " -follow -type f -printf '%f\n' | sort -f " | getline manpage) {
  91.                 # Check for new letter of alphabet
  92.       letter = tolower(substr(manpage,1,1));
  93.       if (letter != last_letter) {
  94.     last_letter = letter;
  95.     letter_index[++num_letters] = letter;
  96.                 # Start a new alphabetic heading
  97.     print "<h2> <a name=\"", letter, "\">", toupper(letter), "</a></h2>" > buffer_tmp;
  98.                 # Print out alphabetic quick index and other links
  99.       }
  100.                 # Split page.n into "page" and "n" and generate an entry
  101.       match(manpage, /[.][^.]+$/);      
  102.       title = substr(manpage, 1, RSTART - 1);
  103.       print "<a href=\"http:/cgi-bin/man2html?", title, "+", section, "\">", title, "(", substr(manpage, RSTART + 1), ")</a>" > buffer_tmp; 
  104.     }
  105.  
  106.     close(buffer_tmp);
  107.  
  108.     print "<p>" > cache_tmp;
  109.  
  110.                 # Print out alphabetic quick index and other links
  111.     for (i = 1; i <= num_letters; i++) {
  112.       print "<a href=\"#" letter_index[i] "\">" toupper(letter_index[i]) "</a>" > cache_tmp;
  113.     }
  114.  
  115.     print "<p><hr>" > cache_tmp;
  116.     print "<a href=\"http:/cgi-bin/man2html\">Return to Main Contents</a>" > cache_tmp;
  117.  
  118.     print "<p>Other sections:" > cache_tmp;
  119.     for (i=1; i<=8; i++) {
  120.       if (i != section) {        # Dont print an entry for the section we are in
  121.     print "<a href=\"http:/cgi-bin/mansec?" i "\">" i ". " sec_name[i] "</a> " > cache_tmp;
  122.       }
  123.     }
  124.     print "<hr><p>" > cache_tmp;
  125.                 # Print out the accumulated index entries
  126.     while ((getline < buffer_tmp)) print > cache_tmp;
  127.     print "<hr><p>" > cache_tmp;
  128.                 # Print out alphabetic quick index and other links
  129.     for (i = 1; i <= num_letters; i++) {
  130.       print "<a href=\"#" letter_index[i] "\">" toupper(letter_index[i]) "</a>" > cache_tmp;
  131.     }
  132.     print "<hr>" > cache_tmp;
  133.     print "<p><a href=\"http:/cgi-bin/man2html\">Return to Main Contents</a>" > cache_tmp;
  134.     print "<p>Other sections:" > cache_tmp;
  135.     for (i=1; i<=8; i++) {
  136.       if (i != section) {        # Dont print an entry for the section we are in
  137.     print "<a href=\"http:/cgi-bin/mansec?" i "\">" i ". " sec_name[i] "</a> " > cache_tmp;
  138.       }
  139.     }
  140.     print "</body>\n</html>" > cache_tmp;
  141.     system("/bin/mv " cache_tmp " " cache);
  142.     system("/bin/rm -f " buffer_tmp);
  143.   }
  144.   system("/bin/cat " cache);
  145.   exit;
  146. }
  147.